package com.tedu.bill.demo1;

import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;

/**
 * Author：毕龙
 * Date: 2024/5/26 14:01
 */
public class TestFile2 {
    public static void main(String[] args) {
        /**
         * 获取文件夹中所有的java文件
         * 过滤文件夹中还有java的文件
         */
        File file = new File("day14/src/com/tedu/bill/demo1");
        File[] files = file.listFiles();
        for (int i = 0; i < files.length; i++) {
            if(files[i].getName().endsWith(".png")){
                System.out.println(files[i].getName());
            }
        }

        System.out.println("================");
        File[] files1 = file.listFiles(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                //System.out.println(dir);
                if( name.endsWith(".java") && dir.toString().equals("day14\\src\\com\\tedu\\bill\\demo1")){
                    return true;
                }
                return false;
            }
        });
        for (File file1 : files1) {
            System.out.println(file1.getName());
        }
        System.out.println("================");
        File[] files2 = file.listFiles(new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                return pathname.toString().endsWith(".java");
            }
        });
        for (File file1 : files2) {
            System.out.println(file1.getName());
        }


    }
}
